/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ipercube.impl.simple;

import com.ipercube.Dimension;
import com.ipercube.model.DimensionHierarchy;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 *
 * @author tartur
 */
public class SimpleDimensionHierarchy implements DimensionHierarchy {

    private List<Dimension> dimensions;

    protected SimpleDimensionHierarchy(){
        dimensions = new ArrayList();
    }

    public void add(Dimension d, int level) {
        dimensions.add(level, d);
    }

    public void add(Dimension d) {
        dimensions.add(d);
    }

    public List<Dimension> getByLevel(int level) {
        return Collections.unmodifiableList(dimensions);
    }

    public int getMaxLevel() {
        return dimensions.size() - 1;
    }

    public List<Dimension> getAllDimensions() {
        return Collections.unmodifiableList(dimensions);
    }

    public void remove(Dimension d) {
        dimensions.remove(d);
    }

    public void removeLevel(int level) {
        dimensions.remove(level);
    }

    public Dimension getById(String id) {
        Dimension d = null;
        for (Dimension dimension : dimensions) {
            if (dimension.getId().equals(id)) {
                d = dimension;
                break;
            }
        }
        return d;
    }

    public int getLevel(Dimension d) {
        return dimensions.indexOf(d);
    }

    public Dimension getDimension(int level) {
        return dimensions.get(level);
    }
}